//重力子弹
module py2Obj {


    export class gravityBullet extends basicObj {
        //保存外部的物理世界
        private time: egret.Timer;
        private bulletType: any;
        public isRun = false;
        public pointList: egret.Point[] = [];
        public shi: any;
        public constructor(world: any, gamePanle: any, romveSkins: any) {
            super(world, gamePanle, romveSkins);
            this.objkind = 104;

        }
        public init() {
            super.init();
        }

        public send(x, y, forcex, forcey) {
            this.m_body.type = 1;
            this.isRun = true;
            this.m_body.velocity = [0, 0];
            this.m_body.damping = 0;
            this.setPostion(x, y);
            this.setForce(forcex, forcey);
        }
        public createMyRigidbody(): p2.Body {
            var world: P2World = this.m_world;
            var skin: MImage = this.createSkin("zhong_png");
            var body: p2.Body = world.createCircleBodyShape(13);
            body.userData.skin = skin;
            body.userData.data = this;
            body.mass = 0;//质量设置为0，就可以按规定方向发射，等发生碰撞之后再给球质量
            //body.gravityScale=0;
            var shape = body.shapes[0];
            shape.collisionGroup = 2;//010与001为0，010与110为1
            // shape.collisionMask=2;
            // trace(shape.collisionGroup,shape.collisionMask)

            return body;
        }
        private createFixedBullet() {

        }

        public runEnd2() {
            var bullet = new py2Obj.basicBullet(this.m_world, this.m_gamePanle, this.m_removeSkins);
            bullet.init();
            bullet.setPostion(this.m_body.position[0], this.m_body.position[1]);
            this.m_gamePanle.doMaterial(bullet.getBody());
            // bullet.setForce(this.vec.x, this.vec.y);
            // this.setChildIndex(this.gun, this.numChildren - 1);
            this.m_body.velocity = [0, 0];
            this.m_body.type = 2;
            this.setPostion(-100, -100);
            this.isRun = false;
            GameControl.GameControlSole.crashGold();
            return bullet;
        }

        public runEnd(x: number, y: number) {
            this.setForce(x, y);//给一个向下的力
            this.m_body.type = 3;//该死的 终于找到你
            this.isRun = null;
        }
        public runEnd1() {
            this.m_body.type = 3;
            this.isRun = true;
        }

        public timerFunc() {
            console.log(88);
        }
        public recyle() {
            this.isRun = true;
            this.m_body.type = 2;
            this.time = new egret.Timer(50, 1);
            this.time.start();//开始计时
            this.time.addEventListener(egret.TimerEvent.TIMER, this.jishi, this);
        }
        public recyle1() {
            this.m_body.velocity = [0, 0];
            this.m_body.type = 2;
            this.setPostion(-100, -100);
            this.isRun = false;
        }
        public jishi() {
            this.isRun = true;
            this.m_body.type = 1;
        }
        public strikeRecyle() {
            this.m_body.type = 3;
        }
		/**
		 * Body.KINEMATIC = 4;
		 * Body.STATIC = 2;
		 * Body.DYNAMIC = 1;
		 */
        public getCollision(otherBody: basicObj) {
            if (otherBody.objkind == 100 || this.m_body.type == 3) {
                return;
            }
            if (otherBody.objkind == 200 || otherBody.objkind == 201) {
                this.recyle1();
            }
            if (otherBody.objkind == 108) {
                this.strikeRecyle();
                var bb = 1;
            }
            if (bb == null) {
                this.recyle();
            }

        }
    }
}